import 'package:boss/ui/widget/center_title_app_bar.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

import 'provider/calendar_provider.dart';
import 'widget/calendar_browser.dart';

Future<List<DateTime>> showCalendar(
  BuildContext context, {
  String title = '选择日期',
  DateTime minDateTime,
  DateTime maxDateTime,
  DateTime startDateTime,
  DateTime endDateTime,
}) {
  return Navigator.push<List<DateTime>>(context, MaterialPageRoute(builder: (context) {
    return Calendar(
      title: title,
      minDateTime: minDateTime,
      maxDateTime: maxDateTime,
      startDateTime: startDateTime,
      endDateTime: endDateTime,
    );
  }));
}

class Calendar extends StatefulWidget {
  final String title;
  final DateTime minDateTime;
  final DateTime maxDateTime;
  final DateTime startDateTime;
  final DateTime endDateTime;

  const Calendar({
    Key key,
    this.title,
    this.minDateTime,
    this.maxDateTime,
    this.startDateTime,
    this.endDateTime,
  }) : super(key: key);

  @override
  _CalendarState createState() => _CalendarState();
}

class _CalendarState extends State<Calendar> {
  @override
  Widget build(BuildContext context) {
    return MultiProvider(
      providers: [
        ChangeNotifierProvider(
          create: (context) => CalendarProvider(
            startDateTime: widget.startDateTime,
            endDateTime: widget.endDateTime,
            minDateTime: widget.minDateTime,
            maxDateTime: widget.maxDateTime,
          ),
        ),
      ],
      child: Scaffold(
        appBar: CenterTitleAppBar(
          title: '选择日期',
        ),
        body: CalendarBrowser(),
      ),
    );
  }
}
